/*
 * CubePuzzle - A 3D puzzle game
 * Copyright (C) 2010  V.Vamsi Krishna
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef __PUZZLE_H__
#define __PUZZLE_H__

#define WIDTH 640
#define HEIGHT 480

#include <vector>
#include <iostream>

using namespace std;
class Puzzle
{
	//single dimension array keeping track of the grid puzzle.
	unsigned int *grid;
	//size of the grid (s x s)
	int size;
	//each layer is defined by the blocks it has which requires just the indices
	vector<int> layers;	
public:
	Puzzle(int size, char layers = 2);
	~Puzzle();

	/* Randomize Grid*/
	void randomizeGrid( char nlayers );
	
	/* rotate a particular layer, clock or anti-clock*/
	void rotLayer(int index, bool clockwise=true);

	/* check if the puzzle has been solved*/
	bool isSolved();

	/* dumps the puzzle data */
	void dumpData();

    /* angle to render the grid at, comes from main.cpp */
	void render(float *angles);

	int getSize();

	unsigned int getNumLayers();
};

#include "texture.h"
#include "TTFFont.h"
#include "TextObject.h"

extern bool g_EnableGrid;
extern double modelview[16], projection[16];
extern int viewport[4];
extern TTFFont *g_HudFont;
extern TTFFont *g_MenuFont;

namespace GLRenderer
{
	static int width;
	static int height;
    static int langle;
    static int indx;
    static Texture *pTexObj;

    static float cx, cy, cz;
    static float ex, ey, ez;

	const int layer_gap = 2;
	const int block_size = 2;
    //initialize opengl for w, h
	void init(int w, int h);
    //the caller sets the lindex which has to be rotated.
    void setIndex(int indx);
    int getIndex();
    //keep updating the angle with which the particular layer is to be rotated.
    bool updateAngle();
    //render the grid all layers full data
	void renderGrid(float *angles, unsigned int *grid, int size, vector <int> &layers);
    void drawCube(float x, float y, float z, float w, float h);
    //function to handle resizing of window
	void resize(int w, int h);
    void set3DProjection(int w, int h);
    void set2DProjection(int w, int h);
	//call this function every time there is a change in grid size
    void setEyeAndCenter(int size, int layers); 
	void setCamera();
}
#endif //__PUZZLE_H__
